home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0885.arc
/
SMALTAL1.LTG
< prev
next >
Wrap
Text File
|
1986-02-27
|
2KB
|
46 lines
Smalltalk LISTING 1:
Filter class definition and methods
Object subclass: #Filter
instanceVariableNames:
'filterBlock ' "Code that does the filtering"
classVariableNames: '' "None"
poolDictionaries: '' "None"
Filter class methods
using: aFilterBlock
"Create a new filter using the specified block."
^self new using: aFilterBlock
Filter methods
from: inStream to: outStream
"Filter from input to output stream, returning output
stream."
inStream do: [:item | "Do for each item in inStream"
((item := filterBlock value: item) isKindOf: String)
ifTrue: [outStream nextPutAll: item]
ifFalse: [outStream nextPut: item]].
^outStream.
fromFile: inFile toFile: outFile
"Filter from the specified input file and append to the
output file. Return the output file name."
^(self "Invoke self with files opened as streams"
from: (Disk file: inFile)
to: (Disk file: outFile) setToEnd)
close file name.
using: aFilterBlock
"Make the specified block be this object's filter block."
filterBlock := aFilterBlock